﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DirectOPCClient
{
   public  class Commons
    {
        //read xml
        public static Dictionary<string,string> ReadXml(string path)
        {
            Dictionary<string,string> dict = new Dictionary<string, string>();
            //将XML文件加载进来
            XDocument document = XDocument.Load(path);
            //获取到XML的根元素进行操作
            XElement root = document.Root;
            //XElement ele = root.Element("items");
            
            //获取根元素下的所有子元素
            IEnumerable<XElement> enumerable = root.Elements();
            foreach (XElement item in enumerable)
            {

                dict.Add(item.Attribute("name").Value, item.Value);
                 //   Console.WriteLine(item.Attribute("name").Value);   //输出 name  name1            

               // Console.WriteLine(item.Value);   //输出 name  name1            
               
            }
            return dict;

        }
    }
}
